package com.healthyeating.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.healthyeating.manage.domain.vo.MenuPlanVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.healthyeating.common.annotation.Log;
import com.healthyeating.common.core.controller.BaseController;
import com.healthyeating.common.core.domain.AjaxResult;
import com.healthyeating.common.enums.BusinessType;
import com.healthyeating.manage.domain.MenuPlan;
import com.healthyeating.manage.service.IMenuPlanService;
import com.healthyeating.common.utils.poi.ExcelUtil;
import com.healthyeating.common.core.page.TableDataInfo;

/**
 * 菜单计划Controller
 *
 * @author 段奇乐
 * @date 2025-03-14
 */
@RestController
@RequestMapping("/manage/menuPlan")
public class MenuPlanController extends BaseController {
    @Autowired
    private IMenuPlanService menuPlanService;

    /**
     * 查询菜单计划列表
     */
    @PreAuthorize("@ss.hasPermi('manage:menuPlan:list')")
    @GetMapping("/list")
    public TableDataInfo list(MenuPlanVo menuPlanVo) {
        startPage();
        List<MenuPlan> list = menuPlanService.selectMenuPlanList(menuPlanVo);
        return getDataTable(list);
    }

    /**
     * 导出菜单计划列表
     */
//    @PreAuthorize("@ss.hasPermi('manage:menuPlan:export')")
//    @Log(title = "菜单计划", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, MenuPlan menuPlan) {
//        List<MenuPlan> list = menuPlanService.selectMenuPlanList(menuPlan);
//        ExcelUtil<MenuPlan> util = new ExcelUtil<MenuPlan>(MenuPlan.class);
//        util.exportExcel(response, list, "菜单计划数据");
//    }

    /**
     * 获取菜单计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:menuPlan:query')")
    @GetMapping(value = "/{menuPlanId}")
    public AjaxResult getInfo(@PathVariable("menuPlanId") Long menuPlanId) {
        return success(menuPlanService.selectMenuPlanByMenuPlanId(menuPlanId));
    }

    /**
     * 新增菜单计划
     */
    @PreAuthorize("@ss.hasPermi('manage:menuPlan:add')")
    @Log(title = "菜单计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MenuPlanVo menuPlanVo) {
        return toAjax(menuPlanService.insertMenuPlan(menuPlanVo));
    }

    /**
     * 修改菜单计划
     */
    @PreAuthorize("@ss.hasPermi('manage:menuPlan:edit')")
    @Log(title = "菜单计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MenuPlan menuPlan) {
        return toAjax(menuPlanService.updateMenuPlan(menuPlan));
    }

    /**
     * 删除菜单计划
     */
    @PreAuthorize("@ss.hasPermi('manage:menuPlan:remove')")
    @Log(title = "菜单计划", businessType = BusinessType.DELETE)
    @DeleteMapping("/{menuPlanIds}")
    public AjaxResult remove(@PathVariable Long[] menuPlanIds) {
        return toAjax(menuPlanService.deleteMenuPlanByMenuPlanIds(menuPlanIds));
    }
}
